package com.huawei;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * Created by Z-hong on 2024/7/18.
 */

public class HJ48 {
    public static class Node{
        int val;
        Node next;
        Node(int val){
            this.val=val;
        }
    }
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int count=sc.nextInt();
        int val=sc.nextInt();
        Node head=new Node(val);
        count--;
        Map<Integer,Node> map=new HashMap<>();
        map.put(val,head);
        for (int i = 0; i < count; i++) {
            int cur_val=sc.nextInt();
            int pre_val=sc.nextInt();
            Node cur=new Node(cur_val);
            map.put(cur_val,cur);
            Node pre=map.get(pre_val);
            if(pre.next==null){
                pre.next=cur;
            }else{
                cur.next=pre.next;
                pre.next=cur;
            }

        }
        int del_val=sc.nextInt();
        if(head.val==del_val){
            head=head.next;
        }else {
            map.forEach((k,v)->{
                if(v.next!=null&&v.next.val==del_val){
                    if(v.next.next!=null){
                        v.next=v.next.next;
                    }else {
                        v.next=null;
                    }

                }
            });

        }
        while(head!=null){
            System.out.print(head.val);
            head=head.next;
            if(head!=null){
                System.out.print(" ");
            }
        }
    }
}
